package com.atguigu.boot;


import com.atguigu.boot.bean.Pet;
import com.atguigu.boot.bean.User;
import com.atguigu.boot.config.Myconfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 主程序类
 * 代表是个springboot应用
 * springboot默认扫描启动类下面的包,但是也可以使用scanBasePackages执行扫描包
 */
@SpringBootApplication(scanBasePackages = "com.atguigu")
public class MainApplication {
    public static void main(String[] args) {
//        //返回ioc容器
        ConfigurableApplicationContext run = SpringApplication.run(MainApplication.class, args);
//        //查看容器的组件
//        String[] beanDefinitionNames = run.getBeanDefinitionNames();
//        for (String beanDefinitionName : beanDefinitionNames) {
//            System.out.println(beanDefinitionName);
//        }
//
//        //从容器中获取组件
//        Pet tom = run.getBean("tom", Pet.class);
//        Pet tom2 = run.getBean("tom", Pet.class);
//
//
//        Myconfig bean = run.getBean(Myconfig.class);
//
//        //如果@Configuration(proxyBeanMethods = true)代理对象调用方法,springboot总会检查这个组件是否在容器中有,如果有就直接拿代理对象,没有就创建普通对象,保持一直 false就相反
//        User user = bean.user01();
//        User user1 = bean.user01();
//        System.out.println(user == user1);
//
//        User user01 = run.getBean("user01", User.class);
//        Pet tom1 = run.getBean("tom", Pet.class);
////如果@Configuration(proxyBeanMethods = true)会成立 false就不会
//        System.out.println(user1.getPet() == tom);
//
//
//        //获取组件
//
//        String[] beanNamesForType = run.getBeanNamesForType(User.class);
//        System.out.println("=======================");
//        for (String s : beanNamesForType) {
//            System.out.println(s);
//        }

        boolean tom = run.containsBean("tom");
        System.out.println("杨琛"+tom);
        boolean user01 = run.containsBean("user01");
        System.out.println("useasedas"+user01);
    }
}
